/**
 * 
 */
package com.srini.servlets;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author A200171
 * 
 */
public class LeaveApplicationServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doGet(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String reason = req.getParameter("reason");
		String from = req.getParameter("leavefrom");
		String to = req.getParameter("leaveto");

		String name = (String) req.getSession().getAttribute("userName");

		DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
		Date fromDate = null, toDate = null;
		try {
			fromDate = format.parse(from);
			toDate = format.parse(to);
		} catch (Exception e) {
			e.printStackTrace();
		}
		Calendar startCal;
		Calendar endCal;
		startCal = Calendar.getInstance();
		startCal.setTime(fromDate);
		endCal = Calendar.getInstance();
		endCal.setTime(toDate);
		System.out.println("Hi {Manager}, \n" + name
				+ " has applied leave from " + from + " to " + to + " for "
				+ reason);
	}
}
